package com.lyy.king.common.core.domain;

import com.lyy.king.common.core.constant.HttpStatus;

import java.util.List;

public class PageResult<T> {
    /**
     * 响应码
     */
    private Integer code;
    /**
     * 响应数据
     *
     */
    private List<T> data;
    /**
     * 总数据量
     */
    private Integer total;
    /**
     * 总页数
     */
    private Integer totalPage;
    /**
     * 当前页数
     */
    private Integer pageIndex;
    /**
     * 每页记录数
     */
    private Integer pageSize;
    /**
     * 当前页结果数量
     */
    private Integer size;

    /**
     * 当前页记录数
     */

    public PageResult() {
    }

    /**
     * 成功响应
     * @param total
     * @return
     */
    public static <T> PageResult<T> success(Integer total,List<T> data,BasePageQuery query){
        PageResult<T> tResult = new PageResult<>();
        tResult.setCode(HttpStatus.SUCCESS);
        tResult.setData(data);
        tResult.setTotal(total);
        tResult.setTotalPage((int) Math.ceil((double)total/query.getPageSize()));
        tResult.setPageSize(query.getPageSize());
        tResult.setPageIndex(query.getPageIndex());
        tResult.setSize(data.size());
        return tResult;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }
}
